<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./js/qs-6.9.4.js"></script>
  <script src="./js/qs-6.9.4.min.js"></script>
</head>

<body>
  <script>
    let qs = Qs;
    // 创建ajax实例对象
    let xhr = new XMLHttpRequest();
    // 打开一个链接
    // get 传递参数 查询字符串 使用qs进行转换
    let params = {
      page: 1,
      pageSize: 10
    };
    let qsObj = qs.stringify(params);
    console.log(qsObj);
    // xhr.open('get', 'http://121.199.0.35:8888/index/carousel/findAll' + '?' + qsObj);
    xhr.open('post', 'http://121.199.0.35:8888/index/carousel/findAll');
    // 设置请求头
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    // xhr.setRequestHeader('Content-Type','application/json');
    // 发送请求
    xhr.send({ id: 1, name: 'zhangsan' });
    xhr.send(qs.stringify({ id: 1, name: 'zhangsan' }));
    // xhr.send(JSON.stringify({id:1,name:'zhangsan'}));
    // 接受响应
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        console.log(xhr.responseText);
      }
    }
  </script>
</body>

</html>